<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="symbolId" />
  </svg>
</template>

<script setup>
import { computed } from 'vue'

/**
 * @description SVG图标组件
 * @param {string} name - 图标名称
 * @param {string} className - 自定义类名
 */
const props = defineProps({
  name: {
    type: String,
    required: true
  },
  className: {
    type: String,
    default: ''
  }
})

// 图标ID
const symbolId = computed(() => `#icon-${props.name}`)

// SVG类名
const svgClass = computed(() => {
  if (props.className) {
    return `svg-icon ${props.className}`
  }
  return 'svg-icon'
})
</script>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
  color: inherit;
  
  // 强制图标继承父元素颜色
  [data-theme='dark'] & {
    color: inherit;
    fill: currentColor;
  }
}
</style> 